import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/clearable_text_field.dart';
import 'package:safetymonitor/app/components/toast_widget.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/core/values/colors.dart';
import 'package:safetymonitor/app/core/values/styles.dart';

import 'common_controller.dart';

///通用界面
class CommonPage extends StatelessWidget {
  CommonPage({super.key});

  final controller = Get.put(CommonController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.Pure_gray_bg,
      appBar: CustomAppBar(
        title: Text(
          controller.key,
          style: TextStyles.black_18,
        ),
        actions: [
          Container(
            margin: EdgeInsets.only(top: 10.w, right: 10.w),
            padding: EdgeInsets.only(left: 5.w, top: 2.w, right: 5.w, bottom: 4.w),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4.w),
              color: Colors.blue,
            ),
            child: Row(
              children: [
                Text(
                  '完成',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 12.sp,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ],
            ),
          ).clickOnce(() {
            Get.back();
            AppToast.show('完成');
          })
        ],
      ),
      body: GetBuilder(
        init: controller,
        builder: (_) {
          return bodyContent();
        },
      ),
    );
  }

  /// 主体内容
  Widget bodyContent() {
    return Padding(
      padding: EdgeInsets.only(top: 20.w),
      child: MultifunctionalClearTextField(
        text: controller.value,
        node: controller.node,
        clickOnce: controller.iconClick,
        onChangedValue: (value) {
          AppToast.showSuccess(value);
        },
      ),
    );
  }
}
